package com.paomi.client.activity.classify;

import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter;
import com.paomi.client.fragment.first.model.NewsJson;
import com.paomi.client.fragment.first.model.TicketJson;
import com.paomi.client.fragment.first.model.TicketListJson;
import com.paomi.client.net.Api;
import com.paomi.client.net.BaseCallback;
import com.paomi.client.net.Constants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;

/**
 * Created by pc on 2018/12/19
 * Describe:
 * com.paomi.client.activity.classify
 */
public class SearchClassifyPresenter extends MvpBasePresenter<SearchClassifyMvpView> {
    private List<TicketJson> ticketJsonList=new ArrayList<>();
    //获取演出列表
    public void getShowList(String content,int page1,String type){//排序规则(默认0) 0 时间 1 热度
        Map<String,String> stringMap=new HashMap<>();
        stringMap.put("content",content);
        stringMap.put("pageNum",""+page1);
        stringMap.put("pageSize",""+Constants.PAGE_SIZE);
        stringMap.put("sort",type);
        Api.getInstanceService(Constants.Ticket_URL).getSearchTicket(stringMap).enqueue(new BaseCallback<TicketListJson>() {
            @Override
            public void onResponse(Call<TicketListJson> call, TicketListJson result) {
                if(page1==1){
                    ticketJsonList.clear();
                }
                ticketJsonList.addAll(result.getReturnData().getData());
                if(isViewAttached()){
                    getView().setShowData(ticketJsonList);
                }
            }
        });
    }

    //获取资讯列表
    public void setInfoData(int pageNme, String content, String classify) {
        Map<String, String> stringMap = new HashMap<>();
        stringMap.put("content", content);
        stringMap.put("pageNum", "" + pageNme);
        stringMap.put("pageSize", "" + Constants.PAGE_SIZE);
        stringMap.put("sort", classify);//0是时间，1是热度
        Api.getInstanceService(Constants.Ticket_URL).getSearchNews(stringMap).enqueue(new BaseCallback<NewsJson>() {
            @Override
            public void onResponse(Call<NewsJson> call, NewsJson result) {
                if(result.getReturnData()!=null){
                    if(isViewAttached()){
                        getView().getInfoData(result.getReturnData().getData());
                    }
                }
            }
        });
    }
}
